//
//  MyBaseTableViewController.swift
//  weibo08
//
//  Created by 陈杰明 on 16/2/28.
//  Copyright © 2016年 JM. All rights reserved.
//

import UIKit

class MyBaseTableViewController: UITableViewController {
    
    var userLogin = MyUserAccountViewModel.sharedInstance.userLogin
    
    //如果用户登录就走父类，如果没有就自定义
    override func loadView() {
        
        userLogin ? super.loadView() : setupVistorView()
    }
    ///设置访问视图
    func setupVistorView() {
        
        self.view = vistorView
        //设置代理
        vistorView.registerDelegate = self
        vistorView.loginDelegate = self
        
        //判断控制器是哪一个加载图片和信息
        if self is MyHomeViewController {
            vistorView.iconViewRotation()
            
        }else if (self is MyMessageViewController) {
            vistorView.setupView("visitordiscover_image_message", label: "登录后，别人评论你的微博，发给你的消息，都会在这里收到通知")
            
        }else if (self is MyDiscoverViewController) {
            vistorView.setupView("visitordiscover_image_message", label: "登录后，最新、最热微博尽在掌握，不再会与实事潮流擦肩而过")
            
        }else if (self is MyProfileViewController) {
            vistorView.setupView("visitordiscover_image_profile", label: "登录后，你的微博、相册、个人资料会显示在这里，展示给别人")
        }
        //设置导航控制器左和右的item
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewRegisterBtnDidClick")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: UIBarButtonItemStyle.Plain, target: self, action: "vistorViewLoginBtnDidClick")
    }
    
    //MARK: - 懒加载
    lazy var vistorView:MyVistorView = MyVistorView()
}

//MARK: - 实现MyVistorViewDelegate
extension MyBaseTableViewController: MyVistorViewDelegate {

    //MARK: - 实现代理方法
    func vistorViewRegisterBtnDidClick() {
        
        let netWork = MyNetWorkTool.sharedInstance
        print("netWork: \(netWork.oauthLogin())")
        
        
    }
    func vistorViewLoginBtnDidClick() {
        
        let oauthVC = MyOauthViewController()
        //包装一个导航控制器
        presentViewController(UINavigationController(rootViewController: oauthVC), animated: true, completion: nil)
    }
}

